package cylicbarrier

import (
	"fmt"
	"sync"

)

type Cylicbarrier struct {
	c       chan int
	counter int
	target  int
	lock    sync.Mutex
}

func (c *Cylicbarrier) Wait() {

	c.counter++
	if c.counter == c.target {
		fmt.Println("notify all")
		c.c <- 1
		c.c <- 1
		c.c <- 1
	} else {
		fmt.Println("wait")
		<-c.c
	}

}

func GetInstance(target int) *Cylicbarrier {
	c := &Cylicbarrier{}
	c.target = target
	c.counter = 0
	c.c = make(chan int, 20)
	return c
}



